/*
package com.example.demo;


import com.example.demo.batch.Person;
import com.example.demo.batch.PersonItemProcessor;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.batch.core.*;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.listener.JobExecutionListenerSupport;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider;
import org.springframework.batch.item.database.JdbcBatchItemWriter;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
import org.springframework.batch.item.file.mapping.DefaultLineMapper;
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.io.PrintStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

@SpringBootApplication
@EnableBatchProcessing
@EnableScheduling
public class DemoApplication implements CommandLineRunner {
    private static final Logger logger = LogManager.getLogger(DemoApplication.class);
    @Autowired
    private JobBuilderFactory jobs;
    @Autowired
    private StepBuilderFactory steps;
    @Autowired
    private JobLauncher jobLauncher;
    @Autowired
    private Job job;

    @Resource
    private DataSource dataSource;
    @Autowired
    private JdbcTemplate jdbcTemplate;


    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(DemoApplication.class);
        springApplication.setBanner(new Banner() {
            @Override
            public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
                out.print("spring boot banner!--------------------------------\n\n\n");
            }
        });
        //事件监听器
        springApplication.addListeners(new ApplicationListener<ApplicationEnvironmentPreparedEvent>() {
            @Override
            public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
                System.out.println("spring boot！环境初始化完成");
            }

        }, new ApplicationListener<ApplicationFailedEvent>() {

            @Override
            public void onApplicationEvent(ApplicationFailedEvent event) {
                System.out.printf("spring boot！启动失败");
            }
        }, new ApplicationListener<ApplicationPreparedEvent>() {
            @Override
            public void onApplicationEvent(ApplicationPreparedEvent event) {

                System.out.printf("spring boot！准备初始化！");

            }
        });
        springApplication.run(args);
        //SpringApplication.run(Application.class, args);
    }

    @Bean
    public FlatFileItemReader<Person> reader() {
        FlatFileItemReader<Person> reader = new FlatFileItemReader<Person>();
        reader.setResource(new ClassPathResource("sample-data.csv"));
        reader.setLineMapper(new DefaultLineMapper<Person>() {{
            setLineTokenizer(new DelimitedLineTokenizer() {{
                setNames(new String[]{"firstName", "lastName"});
            }});
            setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {{
                setTargetType(Person.class);
            }});
        }});
        return reader;
    }

    @Bean
    public PersonItemProcessor processor() {
        return new PersonItemProcessor();
    }


    @Bean
    public JdbcBatchItemWriter<Person> writer() {
        JdbcBatchItemWriter<Person> writer = new JdbcBatchItemWriter<Person>();
        writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Person>());
        writer.setSql("INSERT INTO people (first_name, last_name) VALUES (:firstName, :lastName)");
        writer.setDataSource(dataSource);
        return writer;
    }

    @Bean
    protected Tasklet tasklet() {

        return new Tasklet() {

            @Override
            public RepeatStatus execute(StepContribution contribution,
                                        ChunkContext context) throws Exception {
                return RepeatStatus.FINISHED;

            }
        };

    }


    */
/* @Scheduled(fixedDelay = 10000L)*//*

    public void send() throws Exception {
        JobParameters jobParameters = new JobParametersBuilder()
                .addString("inputResource", "inputResource1")
                // .addDate("date", new Date())
                .toJobParameters();
        jobLauncher.run(job, jobParameters);
    }

    @Bean
    public Job job() throws Exception {
        return this.jobs.get("job").incrementer(new RunIdIncrementer())
                .listener(new JobExecutionListenerSupport() {

                    @Override
                    public void afterJob(JobExecution jobExecution) {
                        if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
                            System.out.printf("!!! JOB FINISHED! Time to verify the results");
                            List<Person> results = jdbcTemplate.query("SELECT first_name, last_name FROM people", new RowMapper<Person>() {
                                @Override
                                public Person mapRow(ResultSet rs, int row) throws SQLException {
                                    return new Person(rs.getString(1), rs.getString(2));
                                }
                            });
                            for (Person person : results) {
                                System.out.printf("Found <" + person + "> in the database.");
                            }

                        }
                    }
                }).flow(step1()).start(step1()).start(step1()).
                        next(step2())
                .end().build();
    }

    @Bean
    protected Step step2() throws Exception {
        return this.steps.get("step2").tasklet(tasklet()).build();
    }

    @Bean
    protected Step step1() throws Exception {
        return this.steps.get("step1").<Person, Person>chunk(10)
                .reader(reader())
                .processor(processor())
                .writer(writer())
                .build();
    }

    @Override
    public void run(String... args) throws Exception {
        logger.info("Spring Boot Ant Example1111111111111111111111111111");
        System.out.printf("Spring Boot Ant Example");
    }
    */
/**
     * 跨域
     *
     * @param registry
     *//*

*/
/*    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/")
                .allowedOrigins("*")
                .allowedMethods("GET", "POST")
                .allowedHeaders("Content-Type:application/json;charset=UTF-8")
                .exposedHeaders("header1", "header2")
                .allowCredentials(false).maxAge(3600);
    }*//*

    */

import org.springframework.context.annotation.Bean;


/**
     * 增加自定义消息转换器
     *
     * @param converters
     *//*

*/
/*    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.add(0, weixinHttpMessageConverter());
        super.extendMessageConverters(converters);
    }*//*


}
*/
